package com.pospi.pospihold.print;

import java.util.LinkedList;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.basewin.aidl.OnPrinterListener;
import com.basewin.utils.AppUtil;

/**
 * 作者: wdh <br>
 * 内容摘要: <br>
 * 创建时间: 2016/7/1 16:06<br>
 * 描述: <br>
 */
public class PrintHelper {

	private static final String TAG = PrintHelper.class.getName();
	// text 模版
	public static Map<String, String> t1_l = PrintClient.getRulesTxt("1",
			"left", "0", "0", "0", "0");
	public static Map<String, String> t2_l = PrintClient.getRulesTxt("2",
			"left", "0", "0", "0", "0");
	public static Map<String, String> t2_c = PrintClient.getRulesTxt("2",
			"center", "0", "0", "0", "0");
	public static Map<String, String> t3_l = PrintClient.getRulesTxt("3",
			"left", "0", "0", "0", "0");
	public static Map<String, String> t3_c = PrintClient.getRulesTxt("3",
			"center", "0", "1", "0", "0");

	public static Map<String, String> tst2 = PrintClient.getRulesTxt("2",
			"center", "0", "1", "0", "0");
	public static Map<String, String> tst3 = PrintClient.getRulesTxt("3",
			"center", "0", "0", "1", "0");
	public static Map<String, String> tst4 = PrintClient.getRulesTxt("2",
			"left", "0", "0", "1", "0");
	public static Map<String, String> tst5 = PrintClient.getRulesTxt("2",
			"right", "0", "0", "1", "0");
	// 二维码 模版
	public static Map<String, String> e1 = PrintClient.getRulestwo_dimension(
			"4", "center", "0");
	// 一维码 模版
	public static Map<String, String> y1 = PrintClient.getRulesone_dimension(
			"2", "center", "1");
	// 图片 模版
	public static Map<String, String> i1 = PrintClient.getRules_Image("center");

	// 底部数据
	public static LinkedList<JSONObject> bottom;

	public static PrintClient.PrintData top;

	public static PrintClient.PrintData bottom0;
	public static PrintClient.PrintData bottom1;
	public static PrintClient.PrintData bottom2;

	static {
		PrintClient p1 = new PrintClient();
		try {
			// top = new PrintClient().setImage(, ).add().getPrintData();
			p1.setText("本人确认以上交易，同意将其记入本卡账户", t1_l).add();
			p1.setText(
					"I ACKNOWLEDGE SATISFACTORY RECEIPT OF RELATIVE GOODS/SERVICE",
					t1_l).add();
			p1.setText("服务热线:" + "95516", t1_l).add();
			String sdkVersion = AppUtil.getProp("sys.pos.main_sdk_version",
					"2.0.0");
			p1.setText("APP版本:" + "1.0.8" + "      SDK版本：" + sdkVersion, t1_l)
					.add();
			bottom0 = p1.getPrintData();

			bottom1 = new PrintClient()
					.setText("BW-P2000-V310003 商户存根(MERCHANT COPY)", t1_l)
					.add().getPrintData();

			bottom2 = new PrintClient()
					.setText("BW-P2000-V310003 持卡人存根(CARDHOLDER COPY)", t1_l)
					.add().getPrintData();
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

	public static OnPrinterListener demoListen;

	static {
		demoListen = new OnPrinterListener() {
			@Override
			public void onError(int i, String s) {
				Log.e(TAG, "onError");
			}

			@Override
			public void onFinish() {
				Log.e(TAG, "onFinish");
			}

			@Override
			public void onStart() {
				Log.e(TAG, "onStart");
			}
		};
	}

	// 交易打印
	public static PrintClient transaction() throws Exception {
		PrintClient p = new PrintClient();
		p.setText("银联POS签购单", t3_c).add();
		p.setText("商户名(MERCHANT NAME):", t2_l).add();
		p.setText("商户编号(MERCHANT NO):", t2_l).add();
		p.setText("终端号(TERMINAL NO):", t2_l).add();
		p.setText("操作员号(OPERATOR NO):", t2_l).add();
		p.setText("收单行(ACOUIRER):", t2_l).add();
		p.setText("发卡行(ISSUER):", t2_l).add();
		p.setText("卡号(CARD NO):", t2_l).add();
		p.setText("123**********456" + "      /s", t2_l).add();
		p.setText("有效期(EXP DATE):", t2_l).add();
		p.setText("交易类别(TRANS TYPE):", t2_l).add();
		p.setText("DOTO 待定交易类型数据:", t3_l).add();
		p.setText("批次号(BATCH NO):", t2_l).add();
		p.setText("凭证号(VOUCHER NO):", t2_l).add();
		p.setText("授权码(AUTH NO):", t2_l).add();
		p.setText("参考号(REFER NO):", t2_l).add();
		p.setText("日期/时间(DATA/TIME):", t2_l).add();
		p.setText("交易金额(AMOUNT):", t2_l).add();
		p.setText("RMB " + "300000000.00", t3_l).add();
		p.setText("备注(REFERENCE) :", t2_l).add();
		p.setText("原授权码(OLD AUTH NO) :", t2_l).add();
		p.setText("持卡人签名(CARDHOLDER SIGNATURE):", t1_l).add();
		p.setText("", t1_l).add();
		p.setText("", t1_l).add();
		p.setText("----------------------", t1_l).add();
		p.setTtitleText("商户存根", t3_c);
		p.addTPrintDataBottom(bottom0);
		p.addTPrintDataBottom(bottom1).TSave();
		p.setTtitleText("客户存根", t3_c);
		p.addTPrintDataBottom(bottom0);
		p.addTPrintDataBottom(bottom2).TSave();
		return p;
	}

	public static PrintClient demo() throws Exception {
		PrintClient p = new PrintClient();
		p.setTTitleImage("print_title.bmp", i1);
		p.setText("银联POS签购单", t3_c).add();
		p.setText("商户名(MERCHANT NAME):", t2_l).add();
		p.setText("商户编号(MERCHANT NO):", t2_l).add();
		p.setText("终端号(TERMINAL NO):", t2_l).add();
		p.setText("操作员号(OPERATOR NO):", t2_l).add();
		p.setText("收单行(ACOUIRER):", t2_l).add();
		p.setText("发卡行(ISSUER):", t2_l).add();
		p.setText("卡号(CARD NO):", t2_l).add();
		p.setText("123**********456" + "      /s", t2_l).add();
		p.setText("有效期(EXP DATE):", t2_l).add();
		p.setText("交易类别(TRANS TYPE):", t2_l).add();
		p.setText("DOTO 待定交易类型数据:", t3_l).add();
		p.setText("批次号(BATCH NO):", t2_l).add();
		p.setText("凭证号(VOUCHER NO):", t2_l).add();
		p.setText("授权码(AUTH NO):", t2_l).add();
		p.setText("参考号(REFER NO):", t2_l).add();
		p.setText("日期/时间(DATA/TIME):", t2_l).add();
		p.setText("交易金额(AMOUNT):", t2_l).add();
		p.setText("RMB " + "300000000.00", t3_l).add();
		p.setText("备注(REFERENCE) :", t2_l).add();
		p.setText("原授权码(OLD AUTH NO) :", t2_l).add();
		p.setText("持卡人签名(CARDHOLDER SIGNATURE):", t1_l).add();
		p.setText("", t1_l).add();
		p.setText("", t1_l).add();
		p.setText("----------------------", t1_l).add();
		p.setTtitleText("商户存根", t3_c);
		p.addTPrintDataBottom(bottom0);
		p.addTPrintDataBottom(bottom1).TSave();
		p.setTtitleText("客户存根", t3_c);
		p.addTPrintDataBottom(bottom0);
		p.addTPrintDataBottom(bottom2).TSave();
		return p;
	}

	public static PrintClient PrintVersion() throws JSONException {
		PrintClient p = new PrintClient();
		p.setText("=======银联EMV参数=======", t2_l).add();
		p.setText("******版本号信息******", t2_l).add();
		p.setText("程序版本号 :" + "P2000", t2_l).add();
		return p;
	}

}
